package com.wteam.dragon.shop.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wteam.dragon.shop.pojo.bean.ProductType;
import com.wteam.dragon.shop.service.ProductTypeService;
import com.wteam.dragon.system.aop.log.log.Log;
import com.wteam.dragon.system.basebean.bean.ResultMessage;
import com.wteam.dragon.system.basebean.vo.PageVo;
import com.wteam.dragon.system.util.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 陈晓辉
 * @Date 2020/6/29 16:00
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "商品类型")
@RequestMapping("productType")
public class ProductTypeController {
    private final ProductTypeService productTypeService;

    @Log("添加商品类型")
    @ApiOperation("添加商品类型")
    @PostMapping("addProductType")
    @PreAuthorize("@el.check('addProductType')")
    public ResultMessage addProductType(String name){
        return productTypeService.addProductType(name);
    }

    @Log("删除商品类型")
    @ApiOperation("删除商品类型")
    @DeleteMapping("delProductType")
    @PreAuthorize("@el.check('delProductType')")
    public ResultMessage delProductType(Long id){
        return productTypeService.delProductType(id);
    }

    @Log("更改商品类型")
    @ApiOperation("更改商品类型")
    @PutMapping("editProductType")
    @PreAuthorize("@el.check('editProductType')")
    public ResultMessage editProductType(Long id, String name){
        return productTypeService.editProductType(id, name);
    }

    @Log("获得商品类型列表")
    @ApiOperation("获得商品类型列表")
    @GetMapping("pageProductType")
    @PreAuthorize("@el.check('pageProductType')")
    public ResultMessage pageProductType(PageVo<ProductType> pageVo){
        Page<ProductType> page = BeanUtil.fromPage(pageVo);
        return productTypeService.pageProductType(page);
    }
}
